<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{baseui/head :: head}">
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta name="description" content="动检通智慧云平台"/>
    <meta name="author" content="牧中(上海)物联网科技有限公司"/>
    <link rel="shortcut icon" href="/webjars/images/favicon.png"/>
    <link rel="stylesheet" href="/webjars/js/layui/css/layui.css" media="all">
    <title>牧中畜牧业大数据智慧云平台V1.0</title>


</head>
<body>
<!--顶部一级导航-->
<th:block th:replace="baseui/topheader :: topheader(1)"/>

<!--动检通菜单-->
<div id="topnav" th:replace="djt/partial/topnav :: topnav(7)"></div>


<div id="cl-wrapper">
    <!--左边导航-->
    <th:block th:replace="djt/partial/cert_left :: nav(2)"/>

    <div class="container-fluid" id="pcont">


        <div class="row">
            <div class="col-md-12">
                <div class="block-flat">
                    <div class="header"><h3>动物A证</h3></div>
                    <div class="content">
                        <div class="table-responsive">
                            <div id="datatable_wrapper"
                                 class="dataTables_wrapper form-inline dt-bootstrap no-footer">


                                <div class="row">

                                    <!-- search-->
                                    <div class="row" style="margin-left: 20px" >
                                        <div style="white-space: nowrap">
                                            <div class="col-sm-2">
                                                <div class="input-group date datetime col-md-5 col-xs-7"
                                                     data-min-view="2" data-date-format="yyyy-mm-dd">
                                                    <input id="start" class="form-control" style="width: 90px;"
                                                           size="16"
                                                           type="text" value="" placeholder="开始时间" readonly>
                                                    <span class="input-group-addon btn btn-primary"><span
                                                            class="glyphicon glyphicon-th"></span></span>
                                                </div>
                                            </div>
                                            <div class="col-sm-2">
                                                <div class="input-group date datetime col-md-5 col-xs-7"
                                                     data-min-view="2" data-date-format="yyyy-mm-dd">
                                                    <input id="end" class="form-control" style="width: 90px;"
                                                           size="16"
                                                           type="text" value="" placeholder="结束时间" readonly>
                                                    <span class="input-group-addon btn btn-primary"><span
                                                            class="glyphicon glyphicon-th"></span></span>
                                                </div>
                                            </div>

                                            <span style="margin-left: 20px">   启运地:
                                                           <select class="select2" style="max-width: 100px;"
                                                                   id="startarea">
                                                           <option value="全部">所有区域</option>
                                                               <span th:each="string :${startList}">
                                                          <option th:value="${string}"
                                                                  th:text="${string}">南漳县</option>
                                                               </span>
                                                                 </select>

                                            </span>
                                            <span style="margin-left: 20px">   目的地:
                                                           <select class="select2" style="max-width: 100px;"
                                                                   id="endarea">
                                                           <option value="">所有区域</option>
                                                               <span th:each="cityAreaDto :${areaList}">
                                                            <optgroup th:label="${cityAreaDto.city}">
                                                                <span th:each="region :${cityAreaDto.regions}">
                                                            <option th:value="${region}"
                                                                    th:text="${region}">南漳县</option>
                                                                    </span>
                                                          </optgroup>
                                                                   </span>
                                                                 </select>

                                            </span>
                                            <span style="margin-left:20px">
                                                作废状态:


                                               <select id="zuofei" class="select2" style="max-width: 80px;">
                                                           <option value='0' selected>请选择</option>
                                                    <option value='1'>正常</option>
                                                    <option value='-1'>作废</option>
                                               </select>

                                         </span>
                                            <span style="margin-left: 20px">
                                                证书状态:

                                                <!--1：不受理， -2：驳回，-3：不发证，0：未提交，1：待处理，2：已受理--待勘察，3、已勘察--待发证，4：已发-->
                                               <select id="status" class="select2" style="max-width: 100px;">
                                                           <option value='5' selected>请选择</option>
                                                    <option value='-1'>不受理</option>
                                                    <option value='-2'>驳回</option>
                                                   <option value='-3'>不发证</option>
                                                   <option value='0'>未提交</option>
                                                    <option value='1'>待处理</option>
                                                   <option value='2'>已受理--待勘察</option>
                                                    <option value='3'>已勘察--待发证</option>
                                                   <option value='4'>已发证</option>
                                               </select>

                                         </span>


                                        </div>
                                    </div>
                                    <div class="row">

                                        <span style="margin-left: 50px">货主: <input id="own" class="form-control layer-date" type="text"> </span>
                                        <span style="margin-left: 50px">编号: <input id="number" class="form-control layer-date" type="text"> </span>
                                        <span style="margin-left: 50px">证书编号: <input id="num" class="form-control layer-date" type="text"> </span>
                                        <span style="margin-left: 50px">
                                                <button class="btn btn-primary" onclick="SearchBtn()">搜索</button>
                                                </span>

                                    </div>
                                    <br/>
                                    <div class="row">
                                        <div class="col-sm-12">


                                            <!-- Table -->
                                            <table id="jqGrid" STYLE="text-align: center"></table>
                                            <div id="jqGridPager"></div>

                                        </div>
                                    </div>


                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


        </div>
    </div>

</div>

<script type="text/javascript" src="/webjars/js/jquery.js"></script>


<script type="text/javascript" src="/webjars/js/jquery.nanoscroller/jquery.nanoscroller.js"></script>
<script type="text/javascript" src="/webjars/js/behaviour/general.js"></script>
<script src="/webjars/js/jquery.ui/jquery-ui.js" type="text/javascript"></script>

<script type="text/javascript" src="/webjars/js/jquery.nestable/jquery.nestable.js"></script>
<script type="text/javascript" src="/webjars/js/bootstrap.switch/bootstrap-switch.min.js"></script>
<script type="text/javascript" src="/webjars/js/bootstrap.datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script src="//cdn.bootcss.com/select2/3.4.5/select2.min.js" type="text/javascript"></script>

<script src="/webjars/js/bootstrap.slider/js/bootstrap-slider.js" type="text/javascript"></script>
<script type="text/javascript" src="/webjars/js/jquery.niftymodals/js/jquery.modalEffects.js"></script>
<script type="text/javascript" src="/webjars/js/bootstrap.summernote/dist/summernote.min.js"></script>

<script type="text/javascript" src="/webjars/js/jquery.magnific-popup/dist/jquery.magnific-popup.min.js"></script>

<script src="/webjars/js/layui/layui.js" charset="utf-8"></script>
<script src="/webjars/js/behaviour/voice-commands.js"></script>
<script src="/webjars/js/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/ecmascript" src="/webjars/jqgrid/js/i18n/grid.locale-cn.js"></script>
<script type="text/ecmascript" src="/webjars/jqgrid/js/jquery.jqGrid.min.js"></script>
<script src="//cdn.bootcss.com/echarts/3.6.2/echarts.min.js"></script>

<script type="text/javascript">
    $(document).ready(function () {

        App.init();

        //请按这个标题： 序号	操作	地区	证章类型	检疫证明编号	货主	启运地	目的地	动物种类	数量	开证日期	开证人	状态
        //grid
        $("#jqGrid").jqGrid({
            url: '/djt/cert/animalalist',
            mtype: "GET",
            styleUI: 'Bootstrap',
            datatype: "json",
            autowidth: true,
            colModel: [
                {
                    label: '<span style="text-align: center">编号</span>',
                    name: 'breedReport.number',
                    key: true,
                    width: 200
                },
                {
                    label: '<span style="text-align: center">证章类型</span>',
                    name: 'breedReport.isToLocal',
                    width: 100,
                    formatter: showcert
                },
                {
                    label: '<span style="text-align: center">状态</span>',
                    name: 'breedReport.status',
                    width: 120,
                    formatter: showstatus
                },
                {label: '<span style="text-align: center">货主</span>', name: 'breedReport.owner', width: 80},
                {
                    label: '<span style="text-align: center">目的地</span>',
                    name: 'breedReport.receiveAddressMap',
                    width: 150,
                    formatter: showend
                },
                {
                    label: '<span style="text-align: center">动物种类</span>',
                    name: 'breedReport.breedType',
                    width: 100,
                    formatter: showanimal
                },
                {label: '<span style="text-align: center">数量</span>', name: 'breedReport.quantity', width: 80},
                {
                    label: '<span style="text-align: center">证书编号</span>',
                    name: 'num',
                    width: 120,
                    formatter: showzhengshu
                },
                {
                    label: '<span style="text-align: center">开证日期</span>',
                    name: 'breedReport.date',
                    width: 180,
                    formatter: ShowDate
                },
                {
                    label: '<span style="text-align: center">开证人</span>',
                    name: 'name',
                    width: 80,
                    formatter: showkaizheng
                },
                {label: '<span style="text-align: center">操作</span>', width: 300, formatter: ShowOpertator}
            ],

            viewrecords: true,
            height: 350,
            rowNum: 20,
            pager: "#jqGridPager"
        });
    });

    function ShowDate(cellvalue, options, rowObject) {
        if (cellvalue != null && cellvalue != "") {
            var timestamp4 = new Date(cellvalue);
            var dt = timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8);
            return dt;
        } else {
            return "";
        }
    }

    function showend(cellvalue, options, rowObject) {
        return cellvalue["city"] + cellvalue["region"] + "";


    }
    function showzhengshu(cellvalue, options, rowObject) {
        if (cellvalue == null || cellvalue == "") {
            return "暂无";
        } else {
            return cellvalue;
        }
    }
    function showkaizheng(cellvalue, options, rowObject) {
        if (cellvalue == null || cellvalue == "") {
            return "暂无";
        } else {
            return cellvalue;
        }
    }

    function showstatus(cellvalue, options, rowObject) {
        /*-1：不受理， -2：驳回，-3：不发证，0：未提交，1：待处理，2：已受理--待勘察，3、已勘察--待发证，4：已发证*/
        switch (Number(cellvalue)) {
            case -1:
                return "不受理";
                break;
            case -2:
                return "驳回";
                break;
            case -3:
                return "不发证";
                break;
            case 0:
                return "未提交";
                break;
            case 1:
                return "待处理";
                break;
            case 2:
                return "已受理--待勘察";
                break;
            case 3:
                return "已勘察--待发证";
                break;
            case 4:
                return "已发证";
                break;
        }
    }

    function SearchBtn() {
        var time1 = $("#start").val();
        var time2 = $("#end").val();
        var startcity = $("#startarea").val();
        var endcity = $("#endarea").val();
        var zuofei = $("#zuofei").val();
        var name = $("#name").val();
        var own = $("#own").val();
        var num = $("#num").val();
        var number = $("#number").val();
        var status = $("#status").val();
        if (time1 == "") {
            time1 = new Date("2000-01-01 :00:00:00");
        } else {
            time1 = new Date(time1);
        }
        if (time2 == "") {
            time2 = new Date();
        } else {
            time2 = new Date(time2);
        }

        var sdata = {   // 构建查询需要的参数
            start: time1,
            end: time2,
            startcity: startcity,
            endcity: endcity,
            zuofei: zuofei,
            name: name,
            own: own,
            num: num,
            number: number,
            status: status
        };

        var postData = $("#jqGrid").jqGrid("getGridParam", "postData");

        $.extend(postData, sdata);

        $("#jqGrid").jqGrid("setGridParam", {
            search: true    // (6)将jqGrid的search选项设为true
        }).trigger("reloadGrid", [{page: 1}]);   // (7)重新载入Grid表格，以使上述设置生效
    }

    function ShowOpertator(cellvalue, options, rowObject) {
        var link;
        var row1 = JSON.stringify(rowObject);
        var row = JSON.stringify(rowObject.breedReport.id);
        link = "<button type='button' class='btn btn-default' onclick=\"window.location.href='/djt/cert/animal_a_detail?id=" + row + "'\">证书查看</button><button type='button' class='btn btn-default' id='" + row1 + "' onclick='select(this.id)'>信息查看</button>";
        return rowObject.id == -1 ? "" : link;
    }
    function showcert(cellvalue, options, rowObject) {
        if (cellvalue == 1)return "B证";
        if (cellvalue == -1)return "A证";

    }
    function showanimal(cellvalue, options, rowObject) {
        /*1、猪 2、牛 3、羊 4、家禽*/
        switch (cellvalue) {
            case 1:
                return "猪";
                break;
            case 2:
                return "牛";
                break;
            case 3:
                return "羊";
                break;
            case 4:
                return "家禽";
                break;
            default :
                return "";

        }
    }


    function Showunit(cellvalue, options, rowObject) {
        var type;
        switch (cellvalue) {
            case 1:
                type = "头";
                break;
            case 2:
                type = "只";
                break;
            case 3:
                type = "羽";
                break;
            case 4:
                type = "克";
                break;
            case 5:
                type = "毫升";
                break;
            case 6:
                type = "头份";
                break;
            case 7:
                type = "kg";
                break;
        }
        return type;
    }


    function select(data) {


        var json = JSON.parse(data);
        var isToLocal = showcert(json.breedReport.isToLocal, null, null);
        var timestamp4 = new Date(json.breedReport.date);
        var dt = timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8);
        var timestamp5 = new Date(json.breedReport.receiveAt);
        var dt1 = timestamp5.toLocaleDateString().replace(/\//g, "-") + " " + timestamp5.toTimeString().substr(0, 8);
        var unit = Showunit(json.breedReport.unit, null, null)
        layui.use(['laypage', 'layer'], function () {
            var $ = layui.jquery, layer = layui.layer;


            layer.open({
                type: 2,
                skin: 'layui-layer-lan',
                area: ['800px', '600px'],
                content: ['/djt/cert/animal_a_detail1', 'no'],
                success: function (layero, index) {
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']];

                    body.find("#breedFactoryName").text(json.breedReport.breedFactoryName);
                    body.find("#number").text(json.breedReport.number);

                    body.find("#name").text(json.name);
                    body.find("#isToLocal").text(isToLocal);

                    body.find("#date").text(dt);
                    body.find("#userName").text(json.breedReport.userName);

                    body.find("#userMobile").text(json.breedReport.userMobile);

                    body.find("#applyReportName").text(json.breedReport.applyReportName);
                    body.find("#unit").text(unit);
                    body.find("#quantity").text(json.breedReport.quantity);


                    body.find("#receiveAddressMap").text(json.breedReport.receiveAddressMap.region);
                    body.find("#receiveAt").text(dt1);
                    body.find("#transportNumber").text(json.breedReport.transportNumber);
                    body.find("#deliverAddress").text(json.breedReport.deliverAddress);


                }
            });


        });
    }
</script>


</body>
</html>
